package org.jeecg.modules.quartz.job;

import java.math.BigDecimal;
import java.util.List;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import io.finer.erp.jeecg.bas.entity.ZrkSalsplan;
import io.finer.erp.jeecg.bas.entity.ZrkShoporder;
import io.finer.erp.jeecg.bas.service.IZrkSalsplanService;
import io.finer.erp.jeecg.bas.service.IZrkShoporderService;
/**
 * 
* @ClassName: SalsPlanJob 
* @Description: 实时监控销售年计划完成情况 
* @author heckerstone heckerstone@163.com
* @date Aug 22, 2020 10:57:10 AM 
*
 */
public class SalsYearPlanJob implements Job {
	@Autowired
	IZrkSalsplanService zrkSalsplanService;
	@Autowired
	private IZrkShoporderService zrkShoporderService;

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		//查询销售计划
		List<ZrkSalsplan> list=zrkSalsplanService.selectByActivePlan();
		if(null!=list&&list.size()>0) {
			for(ZrkSalsplan zrkSalsplan:list) {
				//销售计划分为日计划、月计划、年计划
				if(zrkSalsplan.getPlanType().equals("3")) {
					//年计划
					ZrkShoporder zrkShoporder=zrkShoporderService.selectByActiveYearPlan();
					BigDecimal total=zrkSalsplan.getFinishMoney().add(zrkShoporder.getOrderMoney());
					if(BigDecimal.ZERO.compareTo(total)<0) {
						zrkSalsplan.setFinishMoney(total);
						//更新销售计划完成情况
						zrkSalsplanService.updateById(zrkSalsplan);
					}
				}
			}
		}

	}

}
